//package com.hzy.auth;
//
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.List;
//
///**
// * Created by hongzhiyuanzj on 2018/8/2.
// */
//public class TokenAuthenticationFilter extends OncePerRequestFilter{
//    private AuthenticationManager authenticationManager;
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
//        String authorization = httpServletRequest.getHeader("Authorization");
//        if(authorization==null||!authorization.startsWith(getPrefix(authorization))){
//            filterChain.doFilter(httpServletRequest, httpServletResponse);
//            return;
//        }
//
//        Authentication authResult = authenticationManager.authenticate(buildAuthentication(authorization));
//        SecurityContextHolder.getContext().setAuthentication(authResult);
//        filterChain.doFilter(httpServletRequest, httpServletResponse);
//    }
//
//    private String getPrefix(String authorization){
//        return "Token";
//    }
//
//    private Authentication buildAuthentication(String authorization){
//        String[] auths = authorization.split(" ");
//        return new TokenAuthenticationToken(auths[1]);
//
//    }
//}
//
